package com.datang.petstore.controller;

/*
 * @auther 顶风少年
 * @mail dfsn19970313@foxmail.com
 * @date 2019-11-04 14:04
 * @notify 转发api
 * @version 1.0
 */

import com.datang.petstore.aop.ForbidAnnotation;
import com.datang.petstore.entity.Microblog;
import com.datang.petstore.entity.MicroblogTransmitRecord;
import com.datang.petstore.model.MicroblogTransmitRecordRequest;
import com.datang.petstore.resultpage.Result;
import com.datang.petstore.service.MicroblogTransmitRecordService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MicroblogTransmitRecordController {

    @Autowired
    private MicroblogTransmitRecordService microblogTransmitRecordService;


    /*
     * @author 顶风少年
     * @date 2019/11/5 7:38
     * @mail dfsn199703132038@foxmail.com
     * @throws
     * @param
     * @param microblogTransmitRecordRequest
     * @result com.datang.petstore.resultpage.Result
     * @notify 添加转发
     * version 1.0
     */
    @PostMapping(value = "microblog/transmit")
    @ForbidAnnotation
    public Result addMicroblogTransmitRecord(@RequestBody MicroblogTransmitRecordRequest microblogTransmitRecordRequest) {

        MicroblogTransmitRecord microblogTransmitRecord = new MicroblogTransmitRecord();
        BeanUtils.copyProperties(microblogTransmitRecordRequest, microblogTransmitRecord);

        Microblog microblogr = new Microblog();
        microblogr.setFacilityModel(microblogTransmitRecordRequest.getFacilityModel());
        microblogr.setCountry(microblogTransmitRecordRequest.getCountry());
        microblogr.setProvince(microblogTransmitRecordRequest.getProvince());
        microblogr.setCity(microblogTransmitRecordRequest.getCity());
        microblogr.setDistrict(microblogTransmitRecordRequest.getDistrict());
        microblogr.setAddress(microblogTransmitRecordRequest.getAddress());
        microblogr.setTransmitText(microblogTransmitRecordRequest.getText());
        microblogTransmitRecordService.addMicroblogTransmitRecord(microblogTransmitRecord,microblogr);

        return Result.ok();
    }
}
